<!DOCTYPE html>
<html lang="zh">

<head>
    <meta charset="utf-8">
    <link rel="stylesheet" href="style.css">
    <title>输入框选中交互动效</title>
    <style>
        .app {
            width: 100%;
            height: 100vh;
            position: relative;
            display: flex;
            justify-content: center;
            align-items: center;
        }

        input {
            list-style: none;
            outline-style: none;
        }

        label {
            width: 240px;
            position: relative;
            display: flex;
            align-items: center;
        }

        input {
            width: 240px;
            height: 32px;
            line-height: 32px;
            padding: 0 10px;
            border: 2px solid transparent;
            border-bottom-color: #333;
            background-color: transparent;
            box-sizing: border-box;
            transition: all 0.3s;
            font-size: 14px;
            color: #333;
        }

        span {
            position: absolute;
            font-size: 14px;
            color: #999;
            left: 10px;
            cursor: text;
            z-index: 1;
            transition: all 0.3s;
        }

        label:hover input,
        input:focus {
            border-color: blue;
            border-radius: 8px;
        }

        input:focus+span,
        input:valid+span {
            transform: translateY(-32px);
        }
    </style>
</head>

<body>
    <div class="app">
        <label>
            <input type="text" required>
            <span>用户名</span>
        </label>
    </div>
</body>

</html>